package com.bluesky.javawebbrowser.ui;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Date;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Box;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JToolBar;
import javax.swing.border.BevelBorder;

public class BoxLayoutFrame extends JFrame {
	public BoxLayoutFrame() {
		setSize(350, 300);
		Box box0 = Box.createVerticalBox();
		setContentPane(box0);

		Action fooAction = new MyAction("Foo", new ImageIcon("images/ms.jpg"));
		fooAction.addPropertyChangeListener(new PropertyChangeListener() {

			@Override
			public void propertyChange(PropertyChangeEvent evt) {
				System.out.println("PropertyChanged,old:"+evt.getOldValue()+" new:"+evt.getNewValue());

			}

		});

		JMenuBar menuBar = new JMenuBar();
		menuBar.setBorder(new BevelBorder(BevelBorder.RAISED));

		JMenu menu = new JMenu("Menu");
		JMenuItem menuItem = new JMenuItem(fooAction);
		menu.add(menuItem);
		menuBar.add(menu);
		box0.add(menuBar);

		JToolBar toolbar = new JToolBar();
		JButton button = toolbar.add(fooAction);

		box0.add(toolbar);

		Box box = Box.createHorizontalBox();
		box.add(Box.createHorizontalGlue());
		for (int i = 0; i < 13; i++) {
			Dimension dimButton = new Dimension(80, 30);
			JButton b = new JButton("B" + i);
			b.setMaximumSize(dimButton);
			box.add(b);
			box.add(Box.createHorizontalGlue());

		}

		box.add(Box.createHorizontalGlue());
		box0.add(box);

		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setVisible(true);
		
		

	}

	class MyAction extends AbstractAction {
		public void setName(String value){
			putValue("name", value);
		}
		
		public MyAction(String text, Icon icon) {
			super(text, icon);
		}

		@Override
		public void actionPerformed(ActionEvent e) {
			System.out.println("MyAction performed.");
			setName(new Date().toString());
		}

	}

	public static void main(String[] argv) {
		new BoxLayoutFrame();
	}
}
